import {chatApi, creatConversationApi} from "@/api/commonChat"

const state = {
    name: '',
    role: ''
}

const mutations = {
    SET_NAME: (state, name) => {
        state.name = name
    },
    SET_ROLE: (state, role) => {
        state.role = role
    }
}

const actions = {
    // user login
    chat({ commit }, data) {
        return new Promise((resolve, reject) => {
          chatApi(data).then(res => {
              console.log('chat', res);
              if (res.status === 200) {
                console.log(111);
                resolve({
                    type: "success",
                    message: res.msg,
                    data:res.data
                })
            } else {
                reject({
                    type: "error",
                    message: res.msg
                })
            }
        }).catch(error => {
            reject({
                type: "error",
                message: error.msg
            })
        })
    },  
        )
  },
  creatConversation({ commit },data) {
    return new Promise((resolve, reject) => {
      creatConversationApi(data).then(res => {
          console.log('chat', res);
          if (res.status === 200) {
            console.log(111);
            resolve({
                type: "success",
                message: res.msg,
                data:res.data
            })
        } else {
            reject({
                type: "error",
                message: res.msg
            })
        }
    }).catch(error => {
        reject({
            type: "error",
            message: error.msg
        })
    })
},  
    )
},


// getFileList({ commit },data) {
//   return new Promise((resolve, reject) => {
//     getFileListApi(data).then(res => {
//         console.log('getFileList', res);
//         if (res.status === 200) {
//           console.log(111);
//           resolve({
//               type: "success",
//               message: res.msg,
//               data:res.data
//           })
//       } else {
//           reject({
//               type: "error",
//               message: res.msg
//           })
//       }
//   }).catch(error => {
//       reject({
//           type: "error",
//           message: error.msg
//       })
//   })
// },  
//   )
// }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
